package com.rtx.edi.system.user.controller;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rtx.edi.system.user.service.UserServices;
import com.rtx.model.dto.response.EdiResponse;
import com.rtx.model.po.entity.system.User;

import io.swagger.annotations.Api;

/**
 */
@Controller
@Api(tags = "用户管理维护接口", value = "用户管理维护接口")
public class UserController {

    @Autowired
    private UserServices userServices;

    private static final int PAGESIZE = 20;

    @RequestMapping(value = "user/list", method = RequestMethod.POST)
    @ResponseBody
    public EdiResponse queryList(@RequestBody User request) {
        return userServices.queryUser(request.getPageNum(),request);
    }
    
    @RequestMapping(value = "user/queryuserByid", method = RequestMethod.POST)
    @ResponseBody
    public EdiResponse queryByid(@RequestBody User request) {
        return userServices.queryusebyid(request);
    }


    @RequestMapping(value = "userQuery/{username}", method = RequestMethod.GET)
    @ResponseBody
    public EdiResponse queryUser(@PathVariable String username) {
        return userServices.queryUserByUsername(username);
    }

    @RequestMapping(value = "user/save", method = RequestMethod.POST)
    @ResponseBody
    public EdiResponse save(@RequestBody User user) {
        return userServices.insert(user);
    }

    @RequestMapping(value = "user/delete", method = RequestMethod.POST)
    @ResponseBody
    public EdiResponse delete(@RequestBody List<User> usernamelist) {
    	List<String> usernames = usernamelist.stream().map(temp->temp.getUsername()).collect(Collectors.toList());
        return userServices.deleteByusername(usernames);
    }

    @RequestMapping(value = "user/updatStatus", method = RequestMethod.POST)
    @ResponseBody
    public EdiResponse updatStatus(@RequestBody String[] username) {
        return userServices.updatStatus(username);
    }


    @RequestMapping(value = "isExist/{username}", method = RequestMethod.GET)
    @ResponseBody
    public EdiResponse isExist(@PathVariable String username) {
        return userServices.queryUserByUsername(username);
    }
}
